package com.tongji.housediy.view
{
	import com.tongji.housediy.events.commonEvent.ClearTitleWindowEvent;
	import com.tongji.housediy.events.commonEvent.ListItemMouseEvent;
	import com.tongji.housediy.events.commonEvent.MouseEnabledAdminEvent;
	import com.tongji.housediy.model.GoodsModel;
	import com.tongji.housediy.utils.ConstVariableInventory;
	import com.tongji.housediy.view.renderer.GoodsItemRentererMediator;
	import com.tongji.housediy.vo.Goods;
	
	import flash.events.MouseEvent;
	
	import mx.binding.utils.BindingUtils;
	
	import org.robotlegs.mvcs.Mediator;
	
	/**
	 * 
	 * @author chenchao
	 * 
	 */
	public class GoodsViewStackMediator extends Mediator
	{
		[Inject]
		public var view:GoodsViewStack;
		
		[Inject]
		public var model:GoodsModel;
		
		override public function onRegister():void
		{
			switch (view.id)
			{
				case "doorViewStack":
					//view.goodsList.dataProvider = model.doorArrayCollection;
					BindingUtils.bindProperty(view.goodsList, "dataProvider", model, "doorArrayCollection");
					break;
				case "windowViewStack":
					//view.goodsList.dataProvider = model.windowArrayCollection;
					BindingUtils.bindProperty(view.goodsList, "dataProvider", model, "windowArrayCollection");
					break;
				case "floorViewStack":
					//view.goodsList.dataProvider = model.floorArrayCollection;
					BindingUtils.bindProperty(view.goodsList, "dataProvider", model, "floorArrayCollection");
					break;
				case "furnitureViewStack":
					//view.goodsList.dataProvider = model.furnitureArrayCollection;
					BindingUtils.bindProperty(view.goodsList, "dataProvider", model, "furnitureArrayCollection");
					break;
				case "wallViewStack":
					//view.goodsList.dataProvider = model.wallArrayCollection;
					BindingUtils.bindProperty(view.goodsList, "dataProvider", model, "wallArrayCollection");
					break;
			}
			
			view.addEventListener(ListItemMouseEvent.ITEM_MOUSE_UP, listMouseUpHandler);
			view.addEventListener(MouseEnabledAdminEvent.CLOSE_BTN_CLICKED, closeBtnClickHandler);
		}
		
		
		private function listMouseUpHandler(event:ListItemMouseEvent):void
		{
			GoodsItemRentererMediator.confirmRightTitleWindow = false;
			view.selectedIndex = 1;
			mediatorMap.createMediator(view.goodDetail.picSlideView);
			
			//model.arrangeSizes(view.goodsList.selectedItem as Goods);
			model.arrangeSizes(event.target.data as Goods);
			//this.dispatch(new ClearTitleWindowEvent(ClearTitleWindowEvent.SET_EXIST_WINDOW_FALSE, null, false));
			// 初始化各种 List 的 SelectedIndex
			ConstVariableInventory.retrievedIndex = 0;
		}
		
		private function closeBtnClickHandler(event:MouseEnabledAdminEvent):void
		{
			view.selectedIndex = 0;
			
			// 重置 List SelectedIndex
			ConstVariableInventory.retrievedIndex = -1;
		}
	}
}